import { Controller } from "../../mvc/core/Controller";
import { IZodiacController } from "./interfaces/IZodiacController";
import { IView } from "../../mvc/interfaces/IView";
import { ZodiacModule } from "../../../modules/ZodiacModule";
import { ZodiacIconBtn } from "../view/zodiac/ZodiacIconBtn";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../scene/events/PlayerEvent";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { MyBetData } from "../view/zodiac/betData/MyBetData";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { STwelveAnimalActiveInfoClient } from "../../../Message/Game/STwelveAnimalActiveInfoClient";
import { STwelveAnimalBetInfo } from "../../../Message/Game/STwelveAnimalBetInfo";
import { GameMapUtil } from "../scene/map/GameMapUtil";
import { Alert } from "../../../com/mui/controls/Alert";
import { EPassType } from "../../../Message/Game/EPassType";
import { Language } from "../../../extend/language/Language";
import { STwelveAnimalActiveTimeClient } from "../../../Message/Game/STwelveAnimalActiveTimeClient";
import { IZodiacModule } from "../../../modules/interfaces/IZodiacModule";
type int = number;
//class ZodiacController
    
    export  class ZodiacController extends Controller implements IZodiacController
    {
       

        protected /* override */ initView(): IView
        {
            if (this._zodiacModule == null) 
            {
                this._zodiacModule = new ZodiacModule();
            }
            return this._zodiacModule;
        }

        public get zodiacIcon(): ZodiacIconBtn
        {
            if (this._zodiacIcon == null) 
            {
                this._zodiacIcon = new ZodiacIconBtn();
                this._zodiacIcon.updateIconInfo();
            }
            return this._zodiacIcon;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.ClickZodiacIcon, this.onClickZodiacIcon);
            Dispatcher.addEventListener(EventName.onZodiacBet, this.onBetHandler);
            Dispatcher.addEventListener(EventName.OnGetMoney, this.onGetMoneyHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicTwelveAnimalActiveTime, this.onActiveOpenHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicTwelveAnimalActiveClose, this.onActiveCloseHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateTwelveAnimalBetInfo, this.onZodiacBetInfoHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicTwelveAnimalActiveInfo, this.onActiveInfoHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdateHandler);
            return;
        }

        /* internal  */onGetMoneyHandler(arg1: DataEvent): void
        {
            GameProxy.active.onGetMoney();
            return;
        }

        /* internal  */onBetHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as MyBetData;
            GameProxy.active.onBetAnimal(loc1.type, loc1.betNumber, loc1.money);
            return;
        }

        protected onRoleLevelUpdateHandler(arg1: Object): void
        {
            if (this._activeState) 
            {
                if (cache.role.entityInfo.level >= 70) 
                {
                    this.zodiacIcon.show();
                }
            }
            return;
        }

        /* internal  */onActiveInfoHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as STwelveAnimalActiveInfoClient;
            if (!(this._zodiacModule == null) && !this._zodiacModule.isHide) 
            {
                this._zodiacModule.updateActiveInfo(loc1);
            }
            return;
        }

        /* internal  */onZodiacBetInfoHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as STwelveAnimalBetInfo;
            if (!(this._zodiacModule == null) && !this._zodiacModule.isHide) 
            {
                this._zodiacModule.updateBetInfo(loc1);
            }
            return;
        }

        /* internal  */onClickZodiacIcon(arg1: DataEvent): void
        {
            var e: DataEvent;
            var onClickHandler: Function;

            var loc1;
            e = arg1;
            if (GameMapUtil.curMapState.isCrossMainCity) 
            {
                if (view.isHide) 
                {
                    view.show();
                    GameProxy.active.openZodiac();
                }
                else 
                {
                    view.hide();
                }
            }
            else 
            {
                onClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.YES) 
                    {
                        GameProxy.sceneProxy.pass(EPassType.convert(EPassType._EPassTypeCrossUnique), 1, 0);
                        Alert.resetToDefault();
                    }
                    return;
                }
                Alert.show(Language.getString(200013), null, Alert.YES | Alert.NO, null, onClickHandler);
            }
            return;
        }

        /* internal  */onActiveCloseHandler(arg1: MessageBlock): void
        {
            this._activeState = false;
            this.zodiacIcon.hide();
            return;
        }

        /* internal  */onActiveOpenHandler(arg1: MessageBlock): void
        {
            this._activeState = true;
            if (!arg1.messageBase) 
            {
                return;
            }
            var loc1=arg1.messageBase as STwelveAnimalActiveTimeClient;
            this.zodiacIcon.setTime(loc1.leftSeconds);
            if (this._activeState) 
            {
                if (cache.role.entityInfo.level >= 70) 
                {
                    this.zodiacIcon.show();
                }
                else 
                {
                    this.zodiacIcon.hide();
                }
            }
            return;
        }

        private /* var */_zodiacModule: IZodiacModule;

        private /* var */_zodiacIcon: ZodiacIconBtn;

        private /* var */_activeState: Boolean;
    }
